﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DC.Views
{
    public partial class Form_Prescription : Form
    {
        public Form_Prescription()
        {
            InitializeComponent();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确实要不保存直接退出吗？", "Ask", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.Close();
            }
        }

        Utils.Database DB = Utils.Global.GlobalDB;
        public string patientID = string.Empty;
        public string UserID = string.Empty;
        private void skinButton3_Click(object sender, EventArgs e)
        {
            string content = String.Empty;
            for (int i = 0; i < skinDataGridView1.RowCount - 1; i++)
            {
                content += skinDataGridView1.Rows[i].Cells[0].Value.ToString() + ".";
            }
            string sql2 = string.Format(@"insert into Prescription(Patient_ID,User_ID,Prescription_Content,Prescription_Limit)values(
                                                                            {0},{1},'{2}',{3})",
                                                                    patientID,
                                                                    UserID,
                                                                    content,
                                                                    0
                                                                    ); ;
            if (content == String.Empty) { MessageBox.Show("输出为空！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            else
            {
                DB.Execute(sql2);
                MessageBox.Show("保存成功！", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }

        private void skinDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (skinDataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
            {
                return;
            }
        }
        private void skinDataGridView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                DataGridView.HitTestInfo info = skinDataGridView1.HitTest(e.X, e.Y);
                skinDataGridView1[info.ColumnIndex, info.RowIndex].Selected = true;
            }
        }
    } 
    }

